package com.smart.controller;


import com.smart.pojo.Produce;
import com.smart.pojo.ResultBean;
import com.smart.service.IProduceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyj
 * @since 2023-05-14
 */
@RestController
@RequestMapping("/produce")
public class ProduceController {

    @Autowired
    private IProduceService produceService;

    @GetMapping("queryAll")
    public ResultBean queryAll() {
        System.out.println("获取全部生产任务");
        return ResultBean.success(produceService.queryAll());
    }

    @PostMapping("saveOrUpdate")
    @RequiresPermissions({"produce:save"})
    public ResultBean saveOrUpdate(@RequestBody Produce produce) {
        System.out.println("新增或修改的生产任务：" + produce);
        boolean rs = produceService.saveOrUpdateProduce(produce);
        return rs ? ResultBean.success() : ResultBean.error();
    }

    @DeleteMapping("deleteById/{id}")
    @RequiresPermissions({"produce:del"})
    public ResultBean deleteById(@PathVariable("id") Long id) {
        System.out.println("要删除的生产任务的id：" + id);
        boolean rs = produceService.removeById(id);
        return rs ? ResultBean.success() : ResultBean.error();
    }
}
